package com.intelligence.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.intelligence.entity.model.SaveNewMenuFromRoleModel;
import com.intelligence.entity.pojo.SysRolePermission;
import com.intelligence.entity.pojo.SysRoleUser;
import com.intelligence.mapper.SysRoleMapper;
import com.intelligence.entity.pojo.SysRole;
import com.intelligence.mapper.SysRolePermissionMapper;
import com.intelligence.mapper.SysRoleUserMapper;
import com.intelligence.service.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @description 针对表【sys_role】的数据库操作Service实现
 * @createDate 2024-05-15 19:38:31
 */
@Slf4j
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole>
        implements SysRoleService {
    @Autowired
    private SysRolePermissionMapper sysRolePermissionMapper;

    @Override
    public void saveNewMenuFromRole(SaveNewMenuFromRoleModel saveNewMenuFromRoleModel) {
        log.info("新拥有的菜单是-------->{}", saveNewMenuFromRoleModel);
        //先删除，后保存
        QueryWrapper<SysRolePermission> sysRolePermissionQueryWrapper = new QueryWrapper<>();
        sysRolePermissionQueryWrapper.eq("roleId",saveNewMenuFromRoleModel.getRoleId());
        int delete = sysRolePermissionMapper.delete(sysRolePermissionQueryWrapper);
        log.info("删除了-----》{}条数据",delete);
        SysRolePermission sysRolePermission;
        for (Long l :
                saveNewMenuFromRoleModel.getMenuList()) {
            sysRolePermission = new SysRolePermission();
            sysRolePermission.setPermissionid(l.intValue());
            sysRolePermission.setRoleid(saveNewMenuFromRoleModel.getRoleId());
            sysRolePermissionMapper.insert(sysRolePermission);
        }
    }
}




